package cn.vihub.controller;

import cn.vihub.param.TokenParam;
import cn.vihub.service.TokenService;
import cn.vihub.utils.Result;
import cn.vihub.vo.TokenVo;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("shop-auth/login")
public class LoginController {

    @Autowired
    private TokenService tokenService;

    /**
     * 登录获取token接口
     * @return
     */
    @PostMapping("getAccessToken")
    public Result<TokenVo> getAccessToken(){
        return Result.success(tokenService.createAccessToken(1, "user1"));
    }

    @PostMapping("getRefreshToken")
    public Result<TokenVo> getRefreshToken(@RequestBody TokenParam tokenParam){
        return Result.success(tokenService.createRefreshToken(tokenParam.getRefreshToken()));
    }

}
